package com.example.dingzexi_homework1;

import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.TextView;

public class DetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);

        ImageView imageView = findViewById(R.id.detail_image);
        TextView captionTextView = findViewById(R.id.detail_caption); // 获取 TextView 控件

        // 获取从列表传递过来的数据
        Intent intent = getIntent();
        if (intent != null) {
            String itemName = intent.getStringExtra("item_name");
            int imageResId = intent.getIntExtra("image_res_id", 0); // 提供默认资源ID为0
            String caption = intent.getStringExtra("caption"); // 获取说明文字

            imageView.setImageResource(imageResId);
            captionTextView.setText(caption); // 设置说明文字
        }

    }
}
